package MBeans;

import dao.TipoPromocaoDAO;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import javax.faces.model.DataModel;

import javax.faces.model.ListDataModel;

import model.MarcaProduto;
import model.Promocoes;
import model.Tipopromocao;

@ManagedBean
@RequestScoped
public class TipoPromocaoMBean {
    public TipoPromocaoMBean() {
    }
    
    private Tipopromocao tppromocao = new Tipopromocao();
    private TipoPromocaoDAO dao = new TipoPromocaoDAO();
    private DataModel tpPromocoes;


    public void setTppromocao(Tipopromocao tppromocao) {
        this.tppromocao = tppromocao;
    }

    public Tipopromocao getTppromocao() {
        return tppromocao;
    }

    public void setTpPromocoes(DataModel tpPromocoes) {
        this.tpPromocoes = tpPromocoes;
    }

    public DataModel getTpPromocoes() {
        tpPromocoes = new ListDataModel(dao.findAll());
        return tpPromocoes;
    }
    
    public Object prepareInserir(){
        tppromocao = new Tipopromocao();
        return "cad_tipopromocao";
    }    

    public Object prepareEditar(){
        tppromocao = (Tipopromocao) tpPromocoes.getRowData();
        return "cad_tipopromocao";
    }
    
    public Object prepareExcluir(){
        tppromocao = (Tipopromocao) tpPromocoes.getRowData();
        dao.delete(tppromocao);
        return "list_tipopromocao";
    }       
    
    public Object gravar(){
        dao.insert(tppromocao);
        return "list_tipopromocao";
    }
}
